package com.cjc.common.utils;

/**
 * 响应数据类
 *
 * @Author: 陈江灿
 * @CreateTime: 2025-01-20
 */
public class R<T> {
    /** 成功 */
    public static <T> R ok(int code, String msg, T data){
        R r = new R();
        r.code = code;
        r.msg = msg;
        r.data = data;
        return r;
    }
    public static <T> R ok(int code, T data){
        return R.ok(code, "操作成功", data);
    }
    public static <T> R ok(T data){
        return R.ok(200, data);
    }
    public static <T> R ok(String msg){
        return R.ok(200, msg, null);
    }
    /** 失败 */
    public static  R fail(int code, String msg){
        R r = new R();
        r.code = code;
        r.msg = msg;
        return r;
    }
    public static  R fail(String msg){
        return R.fail(500, msg);
    }
    public static  R fail(){
        return R.fail("操作失败");
    }

    private int code;
    private String msg;
    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}


